package com.eleven.mall.controller;

import com.eleven.mall.pojo.Meta;
import com.eleven.mall.pojo.Rbody;
import com.eleven.mall.pojo.UserIn;
import com.eleven.mall.pojo.entity.Manager;
import com.eleven.mall.pojo.entity.User;
import com.eleven.mall.service.UserService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @Auther: Rui_simple
 * @Date: 2022/10/21 00:40
 * @Description: AuthController
 * @Version 1.0.0
 */
@RestController
@CrossOrigin
@AllArgsConstructor
public class AuthController {

    UserService userService;

    @PostMapping("/login")
    public Rbody login(@RequestBody UserIn user){
        //System.out.println(user);
        Rbody rbody = new Rbody();
        Meta meta = new Meta();
        Manager manager = userService.getUserInfo(user);
        if (manager == null){
            meta.setMsg("用户名或密码错误！");
            meta.setStatus(422);
            rbody.setMeta(meta);
            return rbody;
        }
        rbody.setData(manager);
        return rbody;
    }
}
